function meanValuePlotE1(ave_time,upperB,lowerB,x_mean,name,...
    ylabelstr,a,funcIndex,ns_time,outputIndex)
figure;
% ha = area(ave_time, [lowerB; upperB-lowerB]','FaceColor',[.8 0.8 0.8]);
% set(ha(1), 'FaceColor', 'none') % this makes the bottom area invisible
% set(ha, 'LineStyle', 'none')
hold on
apc3 = 0.775000000000000*0.7;
apc4 = 0.690000000000000*0.7;
apc = [0.100000000000000   0.2000000000000   apc3   apc4];
% apc = [0.100000000000000   0.2000000000000   0.775000000000000   0.690000000000000];
% pp1 = plot(ave_time,upperB,'b.-'); hold on; pp2 = plot(ave_time,lowerB,'b.-');
% pp3 =plot(ave_time,x_mean,'r.-');
% pp1 = plot(ave_time,upperB,'k--',ave_time,lowerB,'k--',...
%     ave_time,x_mean,'k')

% % % E =abs(upperB - x_mean);%
E= std(x_mean)*ones(size(ave_time));
pp1 = errorbar(ave_time(1:4:end),x_mean(1:4:end),E(1:4:end),'ro');
hold on;
if funcIndex == 2
    % fit to cannonical function
       pp2 = plot(ave_time,yd_can(ns_time,a),'k');
       R = corrcoef(x_mean, yd_can(ns_time,a));
       R(1,2)
else
    % fit to linear function
       pp2 = plot(ave_time,yd_L(ns_time,a),'k');
       R = corrcoef(x_mean, yd_L(ns_time,a));
       R(1,2)
end



% set(pp1                            , ...
%   'LineWidth'       , 2           , ...
%   'Marker'          , 'o'         , ...
%   'MarkerSize'      , 6           , ...
%   'MarkerEdgeColor' , 'r'  , ...
%   'MarkerFaceColor' , [1 1 1]  );


% ylim([-1.4,1.4]);
xlim([0 1]);
% if strcmp(name,'SKnee.eps')
%     ylim([0 1.5])
% end
set(pp1,'MarkerSize', 10,'LineWidth',2);
set(pp2,'MarkerSize', 10,'LineWidth',3);
set(gca,'position',apc);
% meanValuePlot(ave_timeLNS,upperBLNS,lowerBLNS,x_meanLNS);
xlabel({'Scaled Time'},'Interpreter','LaTex','FontSize',20)
ylabel({ylabelstr},'Interpreter','LaTex','FontSize',20)
% ylim(ylimit);
% legend('upperbound','lowerbound','mean') %,'robot data'
set(gca,'FontSize',16)
switch outputIndex
    case 1
    l=legend({'$p^H_{hip} \pm \sigma$','$p_{hip}^{F}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 2
        l=legend({'$p^{L,H}_{hip} \pm \sigma$','$p_{hip}^{L,F}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 3
        l=legend({'$m^{H}_{nsl} \pm \sigma$','$m_{nsl}^{F}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 4
        l=legend({'$m^{L,H}_{nsl} \pm \sigma$','$m_{nsl}^{L,F}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 5
        l=legend({'$\theta^{H}_{hip} \pm \sigma$','$\theta_{hip}^{F}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 6
        l=legend({'$\theta^{H}_{sk} \pm \sigma$','$\theta_{sk}^{F}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 7
        l=legend({'$\theta^{H}_{nsk} \pm \sigma$','$\theta_{nsk}^{F}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
end

% l=legend({'$y^H_{M} \pm \sigma$','$y^F$'},1, ...
%    'Location', 'BestOutside', 'Orientation','horizontal',...
%    'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
p = get(l,'position');
% set(l,'Box','off');
set(l, 'position', [0 p(2)-.2 1-0.2 p(4)], 'Box','off');
print(gcf, '-depsc',name)


function ret = yd_can(t,a)
% function 2
ret = exp(-a(4)*t).*(a(1)*cos(a(2)*t)+a(3)*sin(a(2)*t))+a(5);

end

function ret = yd_L(t,a)
    % function 1
        ret = a(1)*t;%+a(1,5)
end

end
